OpenBuildings GenerativeComponents Help

Apply

Iterates through all members of the given list, calling the given function on each member. The given list is not changed.

void Apply(object[] list, void function(object member,
...) func, ...)
object[] Apply(object[] List, void function(object member)
function, , optional additional function Arguments…)

How to Use it

a) One line format:

Apply(scatterPoint, void function(Point currentPoint){
if (currentPoint.Z > 667) expression01 = Add(expression01, currentPoint);})

b) Multi-line format:

void function applier(Point currentPoint)
{
	if (currentPoint.Z > 667) expression01 = Add(expression01,
currentPoint);
}
Apply(scatterPoint, applier);

Options

Optional additional function arguments can be passed into the selector function. Additional arguments to the function are placed after the selector.

Examples

A) Give user feedback if conditions are met

void function applier(Point currentPoint, Point referencePoint)
{
	double distance = Distance(currentPoint, referencePoint);
	if (distance < 7.0)
	Print("The distance of", currentPoint, "is", distance);
};
 Apply(arrayPoint, applier, anchorPoint);

B) Process data if criteria are met

eg. Multiply the Z value of the current point by two and add it to a expression.

void function applier(Point currentPoint, Point referencePoint)
{
	if (currentPoint.X > referencePoint.X) expression01
= Add(expression01, currentPoint.Z * 2);
};
Apply(arrayPoint, applier, anchorPoint);

Note: The apply function cannot be used to return the result of a calculation involving each member of a list. It cannot change the input list in any way. To apply a function to each member of a list simply call a custom defined function that takes in the whole list and processes each member in turn before returning the results.